/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import com.sun.lwuit.Form;
import com.sun.lwuit.Command;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.TextField;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;

/**
 *
 * @author Kvest
 */
public class PasswordEnteringForm extends Form implements ActionListener
{
    public static final int OK_ID = 1;
    public static final int BACK_ID = 2;

    private Command ok;
    private Command back;
    private FormAction listener;
    private TextField password;

    public PasswordEnteringForm(FormAction listener)
    {
        super("Безопасность");
        this.listener = listener;

        init();
    }

    private void init()
    {
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));

        addCommandListener(this);

        back= new Command("Назад", BACK_ID);
        addCommand(back);

        ok = new Command("OK", OK_ID);
        addCommand(ok);

        addComponent(new Label("Пароль:"));
        password = new TextField();
        password.setSelectCommandText("");
        password.setConstraint(TextArea.ANY);
        password.setInputMode("123");
        addComponent(password);
    }

    public void show()
    {
        password.setText("");

        super.show();
    }

    public void actionPerformed(ActionEvent evt)
    {
        if (listener != null)
        {
            listener.commandAction(evt.getCommand().getId());
        }
    }

    public String getPassword()
    {
        return password.getText();
    }
}
